function getList(){
	$.ajax({
	"url":"/get_user/",
	"error":errorAjax,
	"complete":stop_load_pic,
	"beforeSend":start_load_pic,
	"dataType":"jsonp",
	"success":function(data){
		if(!data.status){
			showErrorInfo(data.content)
			return false;
		}
		var data=data.content
			var tab=document.getElementById("tab")	
			for(var i=0;i<data.length;i++){
				var tr=document.createElement("tr")

				var td=document.createElement("td")
				var b=document.createElement("span")
				b.setAttribute("username",data[i].username)
				b.className="glyphicon glyphicon-unchecked check"
				td.appendChild(b)
				tr.appendChild(td)

				var td=document.createElement("td")
				td.textContent=data[i].username;
				tr.appendChild(td)
			
				var td=document.createElement("td")
				td.textContent=data[i].chinese_name;
				tr.appendChild(td)
			
				var td=document.createElement("td")
				td.textContent=data[i].status;
				tr.appendChild(td)

				var td=document.createElement("td")
				td.textContent=data[i].type;
				tr.appendChild(td)

				var td=document.createElement("td")
				var m=document.createElement("button")
				m.className="btn btn-xs btn-primary"
				m.setAttribute("username",data[i].username)
				m.textContent="修改"
				m.onclick=function(){
					var username=this.getAttribute("username")
					window.open ("user.html?username="+username, "_blank", "height=800, width=800, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
					
					
				}
				td.appendChild(m)

				var m=document.createElement("button")
				m.className="btn btn-xs btn-info"
				m.style.marginLeft="4px"
				m.textContent="注销"
				m.setAttribute("username",data[i].username)
				m.onclick=function(){
					var username=this.getAttribute("username")
					removeUser([username])
				}
				td.appendChild(m)
				tr.appendChild(td)
				tab.appendChild(tr)
			}
		
	}
	})
}
function removeUser(data){
	data=JSON.stringify(data)
	$.ajax({
	"url":"/remove_user/",
	"error":errorAjax,
	"complete":stop_load_pic,
	"beforeSend":start_load_pic,
	"data":{"data":data},
	"type":"POST",
	"success":function(data){
		data=JSON.parse(data)
		if(!data.status){
			showErrorInfo(data.content)
			return false;
		}
		alert("操作成功！")
		location.reload()
	}
	})
}
document.getElementById("remove").onclick=function(){
	var data=[]
	$("#tab .check").each(function(){
		if($(this).hasClass("glyphicon-check")){
			data.push(this.getAttribute("username"))	
		}
	})
	if(data.length===0){
		showErrorInfo("还未选中用户！")
		return false;
	}
	removeUser(data)
}
$(document).on("click",".check",function(){
		if($(this).hasClass("glyphicon-unchecked")){
			$(this).removeClass("glyphicon-unchecked").addClass("glyphicon-check")
		}
		else{
			$(this).removeClass("glyphicon-check").addClass("glyphicon-unchecked")
		}
})
document.getElementById("selectAll").onclick=function(){
		if($(this).hasClass("glyphicon-unchecked")){
			$(this).removeClass("glyphicon-unchecked").addClass("glyphicon-check")
			$("#tab span").removeClass("glyphicon-unchecked").addClass("glyphicon-check")
		}
		else{
			$(this).removeClass("glyphicon-check").addClass("glyphicon-unchecked")
			$("#tab span").removeClass("glyphicon-check").addClass("glyphicon-unchecked")
		}
}
getList()
